<input hidden="hidden" id="navValue" value="部门分类">

<div class="page-content">
    <div class="page-header">
        <h1>
            部门管理
            <small>
                <i class="ace-icon fa fa-angle-double-right"></i>
                修改部门分类
            </small>

<!--            <label style="float: right"><form action="" method="get">-->
<!--                    <input type="search" name="keywords" style="height: 35px;" class="input-sm" placeholder="手机号码" aria-controls="dynamic-table" value="">-->
<!---->
<!--                    <button id="searchBtn" type="submit" class="dt-button buttons-collection buttons-colvis btn btn-white btn-primary btn-bold" tabindex="0" aria-controls="dynamic-table" data-original-title="" title="搜索"><span><i class="fa fa-search bigger-110 blue"></i></span></button></form></label>-->

        </h1>
    </div><!-- /.page-header -->

    <div class="row">
        <from class="form-horizontal user-data" role="form">
            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 分类名称: </label>

                <div class="col-sm-5">
                     <input type="text" name="name" placeholder="分类名称" class="col-xs-10 col-sm-9" value="{$item->name}">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 业绩分红: </label>

                <div class="col-sm-5">
                    <input type="text" name="per" placeholder="请填写数字" class="col-xs-10 col-sm-3" value="{$item->per}" > <span style="line-height: 35px; font-size: 20px;margin-left: 5px;"> %</span>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 人数设置: </label>

                <div class="col-sm-5">

                </div>
            </div>
            {foreach $levels as $val}
            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> {$val['name']}: </label>


                <div class="col-sm-1">
                    <input type="text" placeholder="人数" mark="{$val['id']}" class="col-xs-10 col-sm-10" value="{$val['value']}" {if !$val['checked'] }readonly="readonly"{/if}>
                </div>
                <div class="col-sm-3">
                    <label style="padding-top: 5px;">
                        <input name="switch-field-1" class="ace ace-switch ace-switch-6 checkBtn" type="checkbox" {if $val['checked'] }checked{/if}>
                        <span class="lbl"></span>
                    </label>
                </div>
            </div>
            {/foreach}

            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 是否启用: </label>

                <div class="col-sm-3">
                    <label style="padding-top: 5px;">
                        <input name="switch-field-1" class="ace ace-switch ace-switch-1 statusValue" type="checkbox" {if     $item->status eq 1}checked{/if}>
                        <span class="lbl"></span>
                    </label>
                </div>
            </div>


            <div class="col-md-offset-3 col-md-9">
                <button class="btn btn-info saveBtn" type="button">
                    <i class="ace-icon fa fa-check bigger-110"></i>
                    确认修改
                </button>

                <button class="btn" type="reset">
                    <i class="ace-icon fa fa-undo bigger-110"></i>
                    取消
                </button>
            </div>
        </from>

    </div><!-- /.row -->
</div>

<script>
    $(function () {
        $('.checkBtn').change(function () {
            var temp = $(this).parents('.form-group').find("input[type='text']");
            if($(this).is(':checked')){
                temp.attr('readonly',false);
            }else{
                temp.val(0);
                temp.attr('readonly',true);
            }
        });

        $('.saveBtn').click(function () {
            var need = new Array();
            var name = $("input[name='name']").val();
            var per = parseInt($("input[name='per']").val());
            if($(".statusValue").is(":checked")){
                var status = 1;
            }else{
                var status = 0;
            }

            $('.checkBtn').each(function () {
                if($(this).is(':checked')){
                    var inpt = $(this).parents('.form-group').find('input[type="text"]');
                    var key = inpt.attr('mark');
                    var val = inpt.val();
                    need[key] = val;
                }
            });

            if(need.length == 0) {
                layer.msg('请设置部门人员组成',{icon:5});
                return false;
            }
            need = JSON.stringify(need);

            if(name == ''){
                layer.msg('请编写部门名称',{icon:5});
                return false;
            }

            if(per < 0 || per > 100){
                layer.msg('请填入正常的收入百分比',{icon:5});
                return false;
            }

            var data = {name:name,per:per,need:need,status:status};
            $.post(location.href,data,function (e) {
                if(e.code == 200){
                    layer.msg('修改分类成功',{icon:6});
                    self.setInterval(function () {
                        location.href = location.href;
                    },2000);
                }else{
                    layer.msg(e.message,{icon:5})
                }
            },'json');


        });
    })


</script>